package com.jinhua.huaojcodesandbox.model.enums;

import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 题目提交判题信息枚举类
 */
public enum QuestionSubmitJudgeInfoMessageEnum {

    ACCEPTED("判题成功","accept"),
    COMPILING("编译中","compiling"),
    WRONG_ANSWER("答案错误","wrong answer"),
    COMPILE_ERROR("编译错误","compile error"),
    MEMORY_LIMIT_EXCEEDED("内存超出错误","memory limit exceeded"),
    TIME_LIMIT_EXCEEDED("时间超出错判","time limit exceeded"),
    OUTPUT_LIMIT_EXCEEDED("输出溢出错误","output limit exceeded"),
    DANGEROUS_OPERATION("危险操作","dangerous operation"),
    RUNTIME_ERROR("运行错误","runtime error"),
    UNKNOW_ERROR("未知错误","unknow error");

    private final String text;

    private final String value;

    QuestionSubmitJudgeInfoMessageEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static QuestionSubmitJudgeInfoMessageEnum getEnumByValue(String value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (QuestionSubmitJudgeInfoMessageEnum anEnum : QuestionSubmitJudgeInfoMessageEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

    public String getValue() {
        return value;
    }

    public String getText() {
        return text;
    }
}
